﻿using EmoneyWeiXinBLL;
using EmoneyWeiXinCommon;
using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ActivtyUI.Controllers
{
    public class CommonController : Controller
    {

        string currOpenid
        {
            get
            {
                return Request["openid"];
                // return "123123123";
            }
        }



        [HttpPost]
        public ActionResult TiXian()
        {

            string actName = Request["actName"];
            if (currOpenid != null && actName != null)
            {

                double money;
                string result;
                ActivityDataBLL.LockRedBag(currOpenid, actName, out money, out result);
                if (result == "")
                {

                    string orderNum = "";
                    string sendMessage;
                    //因为接口的单位是分，所以用money*100
                    string sendBagResult = "";
                    if (System.Configuration.ConfigurationManager.AppSettings["isrealySendBag"] == "1")
                    {
                        //sendBagResult = WeiXinPayBLL.sendRedBag(currOpenid, money * 100, out orderNum, this.wxInfo, out sendMessage);
                    }
                    MyTrace.get().add("sendBagResult：" + sendBagResult + ",money:" + money + ", openId:" + currOpenid);
                    ActivityDataBLL.UpadateRedBag2getted(currOpenid, actName, sendBagResult == "", money);
                    if (sendBagResult == "")
                    {
                        return Content("提现成功");
                    }
                    else
                    {
                        if (sendBagResult == "NOTENOUGH")
                        {
                            return Content("不好意思，红包已经领完了，感谢您的参与！");
                        }
                        else
                        {
                            return Content("红包提取失败,请稍后重试！");
                        }
                    }


                }
                else
                {
                    return Content("红包提取失败,请稍后重试！");
                }
            }
            else
            {
                return Content("缺少参数");
            }

        }


        public ActionResult ErrorPage()
        {
            string msgCode = Request["msg"];
            string msg = string.Empty;
            switch (msgCode)
            {
                case "uaErr": msg = "请在微信中打开！"; break;
                case "notOpen": msg = "活动还没开始！"; break;
            }

            return Content("<h1>"+msg+"</h1>");
        }
    }

}
